-
Notifications
You must be signed in to change notification settings - Fork 180
sim: call .aclose()
on TickTrigger
in .until()
and .repeat()
#1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Otherwise, when used together with asyncio, the following warning will be printed for each use of `.until()`/`.repeat()`: E: asyncio: Task was destroyed but it is pending! task: <Task pending name='Task-2' coro=<<async_generator_athrow without __name__>()>> /usr/lib/python3.13/asyncio/base_events.py:744: RuntimeWarning: coroutine method 'aclose' of 'TickTrigger.__aiter__' was never awaited
f3ac270
I am unfortunately running into random failures with this change in my testcases:
I'm wondering, why the code needs to be that complex? Can't we simply do async for clk, rst, *values, done in self.sample(condition):
if rst:
raise DomainReset
if done:
return tuple(values) That also fixes the problem for me. The other code segment would probably be written as count = operator.index(count)
if count <= 0:
raise ValueError(f"Repeat count must be a positive integer, not {count!r}")
result = None
async for i, (clk, rst, *values) in enumerate(self):
if i >= count:
break
if rst:
raise DomainReset
assert clk
result = tuple(values)
return result but I have not tested that. |
Yes, I've seen these failures too. |
Would you like to submit your changes as a PR? |
Alright, glad I don't need to build a simplified test case to generate it.
Thinking about it some more, I am not sure if my proposed fix actually calls I tried async with contextlib.aclosing(self.sample(condition).__aiter__()) as tick:
async for clk, rst, *values, done in tick:
if rst:
raise DomainReset
if done:
return tuple(values) but ran into the same issues that the manual handlin in |
Truth be told, I don't actually understand the semantics of / need for |
Not to prove something to myself, no, but it might be quite useful to have one for the purpose of understanding this problem better, and also in order to have a regression test. I think asyncio collects all of the async generators you await and then calls |
Otherwise, when used together with asyncio, the following warning will be printed for each use of
.until()
/.repeat()
: